﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace DryWCS.App.Validation
{
    public class NotNumberValidation : ValidationRule
    {
        public float MaxValue { get; set; } = float.MaxValue;
        public float MinValue { get; set; } = float.MinValue;
        public string NotNumMsg { get; set; }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            MaxValue = 1000000;
            MinValue = -1000000;
            float number;
            if (!float.TryParse((string)value, out number))
            {
                return new ValidationResult(false, NotNumMsg);
            }

            if (number < MinValue || number > MaxValue)
            {
                return new ValidationResult(false, string.Format("Number out of range ({0} - {1})", MinValue, MaxValue));
            }

            return ValidationResult.ValidResult;
        }
    }
}
